importPackage(net.sf.odinms.client);
importPackage(net.sf.odinms.server.maps);

var status = -1;
var chosen = 0;

function start() {
    action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
        	cm.dispose();
	} else {
        	if (mode == 1) {
            		status++;
		} else {
            		status--;
        	}
        	if (status == 0) {
			if(cm.getChar().getMapId() == 980000000) {
				if (cm.getChar().getParty() != null) {
					if (cm.isLeader()) {
						if (cm.checkPartyPlayersMap()) {
							var text = cm.checkCPQMaps();
							text += "\r\n#L6# How to play#l#k";
							cm.sendSimple(text);
						} else {
							cm.sendOk("Tell all your members to gather in this map");
							cm.dispose();
						}
					} else {
						cm.sendOk("Let your leader talk to me");
						cm.dispose();
					}
				} else {
					cm.sendOk("You must be in a party to do CPQ");
					cm.dispose();
				}
			} else {
				cm.sendSimple("What do you want to do?\r\n#L1#Go to the carnival PQ#l\r\n#L2#Trade #i4001129# for items#k#l");
			}
		} else if (status == 1) {
			if (cm.getChar().getMapId() == 980000000) {
				chosen = selection;
				if (chosen != 6) {
					if (cm.getCharQuantity((980000100 + (chosen * 100))) > 0) {
						if (chosen >= 0 && chosen <= 3) {
							if (cm.getPartyMembers() >= 2 && cm.getPartyMembers() <= 4) {
								cm.warpParty((980000100 + (chosen * 100)));
								cm.setPartyBlue();
							} else {
								cm.sendOk("Your party must consist of 2 - 4 members");
							}
						} else {
							if (cm.getPartyMembers() >= 3 && cm.getPartyMembers() <= 6) {
								cm.warpParty((980000100 + (chosen * 100)));
								cm.setPartyBlue();
							} else {
								cm.sendOk("Your party must consist of 3 - 6 members");
							}
						}
						cm.dispose();
					} else {
						if (chosen >= 0 && chosen <= 3) {
							if (cm.getPartyMembers() >= 2 && cm.getPartyMembers() <= 4) {
								cm.warpParty((980000100 + (chosen * 100)));
								cm.setPartyRed();
							} else {
								cm.sendOk("Your party must consist of 2 - 4 members");
							}
						} else {
							if (cm.getPartyMembers() >= 3 && cm.getPartyMembers() <= 6) {
								cm.warpParty((980000100 + (chosen * 100)));
								cm.setPartyRed();
							} else {
								cm.sendOk("Your party must consist of 3 - 6 members");
							}
						}
						cm.dispose();
					}
				} else {
					cm.sendOk("During the carnival PQ you try to kill as many monsters, and thus gain as much as CP as you can. Using CP you can spawn monsters, cast a buff on the enemy, or strengthen the enemy monsters. During Carnival PQ you will collect Maple Coins, you can trade them with me for items.");
					cm.dispose();
				}
			} else {
				if (selection == 1) {
					if (cm.getChar().getMapId() != 910000000) {
						cm.getPlayer().saveLocation(SavedLocationType.MC);
					}
					cm.warp(980000000);
					cm.dispose();
				} else {
					if (cm.itemQuantity(4001129) >= 1) {
						cm.sendOk("Good, you have #b" + cm.itemQuantity(4001129) + "#k maple coin(s)\r\nI am still in #rTesting#k phase\r\nPlease come back later");
						cm.dispose();
					} else {
						cm.sendOk("You don't have any #i4001129#");
						cm.dispose();
					}
				}
			}
		}
	}
}